
import java.util.Map;
import java.util.Objects;
import java.util.HashMap;

public class 使用map {
    public static void main(String[] args) {
        //test1();
        test2();
    }
    static void test1(){
        Student s=new Student("xiao Zhang",78);
        Map<String,Student> map=new HashMap<>();
        map.put("Xiao Zhang", s);
        Student target=map.get("Xiao Zhang");
        System.out.println(target==s);
        System.out.println(target.getScore());
        Student another=map.get("Bob");
        System.out.println(another);
    }
    static void test2(){
        Map<String,Integer> map=new HashMap<>();
        map.put("apple",123);
        map.put("pear",234);
        map.put("banana",456);
        for(String key:map.keySet()){
            Integer value=map.get(key);
            System.out.println(key+" = "+value);
        }
    }
}
class Student{
    String name;
    int score;
    public Student(String name,int score){
        this.name=name;
        this.score=score;
    }
    public String getName(){
        return name;
    }
    public int getScore(){
        return score;
    }
}
class Person{
    String firstName;
    String lastName;
    int age;
    public Person(String firstName,String lastName,int age){
        this.firstName=firstName;
        this.lastName=lastName;
        this.age=age;
    }
    @Override
    public boolean equals(Object o){
        if(o instanceof Person){
            Person p=(Person) o;
            return Objects.equals(this.lastName, p.firstName)&&Objects.equals(this.lastName, p.lastName)&&this.age==p.age;
        }
        else{
            return false;
        }
    }
    @Override
    int hashCode(){
        return Objects.hash(firstName,lastName,age);
    }
}